// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-14 15:37
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.Find.BinarySearch;

public class BinarySearch {
    public static void main(String[] args) {
        int[] nums = {1, 3, 6, 8, 22, 101, 325, 666, 888};
        int aim = 100;
        int r = bSearchT(nums, 100);
        System.out.println("r = " + r);
        System.out.println("nums[r] = " + nums[r]);

    }

    private static int bSearchT(int[] nums, int aim) {
        int n = nums.length, l = 0, r = n - 1, mid = 0;
        while (l < r) {
            mid = l + r + 1 >> 1;
            if (nums[mid] <= aim) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        return r;
    }


}
